// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ingest
{
	public sealed partial class Pipeline
	{
		[JsonInclude]
		[JsonPropertyName("description")]
		public string? Description { get; set; }

		[JsonInclude]
		[JsonPropertyName("on_failure")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? OnFailure { get; set; }

		[JsonInclude]
		[JsonPropertyName("processors")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? Processors { get; set; }

		[JsonInclude]
		[JsonPropertyName("version")]
		public long? Version { get; set; }
	}

	public sealed partial class PipelineDescriptor<TDocument> : SerializableDescriptorBase<PipelineDescriptor<TDocument>>
	{
		internal PipelineDescriptor(Action<PipelineDescriptor<TDocument>> configure) => configure.Invoke(this);
		public PipelineDescriptor() : base()
		{
		}

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? OnFailureValue { get; set; }

		private ProcessorContainerDescriptor<TDocument> OnFailureDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>> OnFailureDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>>[] OnFailureDescriptorActions { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? ProcessorsValue { get; set; }

		private ProcessorContainerDescriptor<TDocument> ProcessorsDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>> ProcessorsDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor<TDocument>>[] ProcessorsDescriptorActions { get; set; }

		private string? DescriptionValue { get; set; }

		private long? VersionValue { get; set; }

		public PipelineDescriptor<TDocument> OnFailure(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? onFailure)
		{
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureValue = onFailure;
			return Self;
		}

		public PipelineDescriptor<TDocument> OnFailure(ProcessorContainerDescriptor<TDocument> descriptor)
		{
			OnFailureValue = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptor = descriptor;
			return Self;
		}

		public PipelineDescriptor<TDocument> OnFailure(Action<ProcessorContainerDescriptor<TDocument>> configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptorAction = configure;
			return Self;
		}

		public PipelineDescriptor<TDocument> OnFailure(params Action<ProcessorContainerDescriptor<TDocument>>[] configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = configure;
			return Self;
		}

		public PipelineDescriptor<TDocument> Processors(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? processors)
		{
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsValue = processors;
			return Self;
		}

		public PipelineDescriptor<TDocument> Processors(ProcessorContainerDescriptor<TDocument> descriptor)
		{
			ProcessorsValue = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptor = descriptor;
			return Self;
		}

		public PipelineDescriptor<TDocument> Processors(Action<ProcessorContainerDescriptor<TDocument>> configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptorAction = configure;
			return Self;
		}

		public PipelineDescriptor<TDocument> Processors(params Action<ProcessorContainerDescriptor<TDocument>>[] configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = configure;
			return Self;
		}

		public PipelineDescriptor<TDocument> Description(string? description)
		{
			DescriptionValue = description;
			return Self;
		}

		public PipelineDescriptor<TDocument> Version(long? version)
		{
			VersionValue = version;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (OnFailureDescriptor is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, OnFailureDescriptor, options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorAction is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(OnFailureDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorActions is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				foreach (var action in OnFailureDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(action), options);
				}

				writer.WriteEndArray();
			}
			else if (OnFailureValue is not null)
			{
				writer.WritePropertyName("on_failure");
				JsonSerializer.Serialize(writer, OnFailureValue, options);
			}

			if (ProcessorsDescriptor is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, ProcessorsDescriptor, options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorAction is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(ProcessorsDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorActions is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				foreach (var action in ProcessorsDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor<TDocument>(action), options);
				}

				writer.WriteEndArray();
			}
			else if (ProcessorsValue is not null)
			{
				writer.WritePropertyName("processors");
				JsonSerializer.Serialize(writer, ProcessorsValue, options);
			}

			if (!string.IsNullOrEmpty(DescriptionValue))
			{
				writer.WritePropertyName("description");
				writer.WriteStringValue(DescriptionValue);
			}

			if (VersionValue is not null)
			{
				writer.WritePropertyName("version");
				JsonSerializer.Serialize(writer, VersionValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class PipelineDescriptor : SerializableDescriptorBase<PipelineDescriptor>
	{
		internal PipelineDescriptor(Action<PipelineDescriptor> configure) => configure.Invoke(this);
		public PipelineDescriptor() : base()
		{
		}

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? OnFailureValue { get; set; }

		private ProcessorContainerDescriptor OnFailureDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor> OnFailureDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor>[] OnFailureDescriptorActions { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? ProcessorsValue { get; set; }

		private ProcessorContainerDescriptor ProcessorsDescriptor { get; set; }

		private Action<ProcessorContainerDescriptor> ProcessorsDescriptorAction { get; set; }

		private Action<ProcessorContainerDescriptor>[] ProcessorsDescriptorActions { get; set; }

		private string? DescriptionValue { get; set; }

		private long? VersionValue { get; set; }

		public PipelineDescriptor OnFailure(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? onFailure)
		{
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureValue = onFailure;
			return Self;
		}

		public PipelineDescriptor OnFailure(ProcessorContainerDescriptor descriptor)
		{
			OnFailureValue = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptor = descriptor;
			return Self;
		}

		public PipelineDescriptor OnFailure(Action<ProcessorContainerDescriptor> configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorActions = null;
			OnFailureDescriptorAction = configure;
			return Self;
		}

		public PipelineDescriptor OnFailure(params Action<ProcessorContainerDescriptor>[] configure)
		{
			OnFailureValue = null;
			OnFailureDescriptor = null;
			OnFailureDescriptorAction = null;
			OnFailureDescriptorActions = configure;
			return Self;
		}

		public PipelineDescriptor Processors(IEnumerable<Elastic.Clients.Elasticsearch.Ingest.ProcessorContainer>? processors)
		{
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsValue = processors;
			return Self;
		}

		public PipelineDescriptor Processors(ProcessorContainerDescriptor descriptor)
		{
			ProcessorsValue = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptor = descriptor;
			return Self;
		}

		public PipelineDescriptor Processors(Action<ProcessorContainerDescriptor> configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorActions = null;
			ProcessorsDescriptorAction = configure;
			return Self;
		}

		public PipelineDescriptor Processors(params Action<ProcessorContainerDescriptor>[] configure)
		{
			ProcessorsValue = null;
			ProcessorsDescriptor = null;
			ProcessorsDescriptorAction = null;
			ProcessorsDescriptorActions = configure;
			return Self;
		}

		public PipelineDescriptor Description(string? description)
		{
			DescriptionValue = description;
			return Self;
		}

		public PipelineDescriptor Version(long? version)
		{
			VersionValue = version;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (OnFailureDescriptor is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, OnFailureDescriptor, options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorAction is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(OnFailureDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (OnFailureDescriptorActions is not null)
			{
				writer.WritePropertyName("on_failure");
				writer.WriteStartArray();
				foreach (var action in OnFailureDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else if (OnFailureValue is not null)
			{
				writer.WritePropertyName("on_failure");
				JsonSerializer.Serialize(writer, OnFailureValue, options);
			}

			if (ProcessorsDescriptor is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, ProcessorsDescriptor, options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorAction is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(ProcessorsDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (ProcessorsDescriptorActions is not null)
			{
				writer.WritePropertyName("processors");
				writer.WriteStartArray();
				foreach (var action in ProcessorsDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ProcessorContainerDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else if (ProcessorsValue is not null)
			{
				writer.WritePropertyName("processors");
				JsonSerializer.Serialize(writer, ProcessorsValue, options);
			}

			if (!string.IsNullOrEmpty(DescriptionValue))
			{
				writer.WritePropertyName("description");
				writer.WriteStringValue(DescriptionValue);
			}

			if (VersionValue is not null)
			{
				writer.WritePropertyName("version");
				JsonSerializer.Serialize(writer, VersionValue, options);
			}

			writer.WriteEndObject();
		}
	}
}